import { Component } from '@angular/core';
import { User } from './user';

import { OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { UserService } from './user.service';

@Component({
  selector: 'my-users',
  templateUrl: './user.component.html'
})

export class UserComponent implements OnInit {
  ngOnInit() {
    this.getUsers();
  }

  users: User[];
  selectedUser: User;

  onSelect(user: User) { 
    this.selectedUser = user; 
  }
  onNew() {this.selectedUser = new User(); }

  constructor(
    private router: Router,
    private userService: UserService) {
  }

  getUsers() {
    this.userService.getUsers().then(users => this.users = users);
  }
}
